package com.walle.concurrenttest.pattern.balking;

import java.util.Random;

/**
 * @author zhangjiapeng
 * @Package com.walle.concurrenttest.pattern.balking
 * @Description: ${todo}
 * @date 2019/2/19 11:32
 */
public class ChangeThread implements Runnable {

    private Random random;

    private Data data;

    public ChangeThread(Data data) {
        this.data = data;
        random = new Random();
    }

    @Override
    public void run() {
        try {
            for (int i = 0; i < 100; i++) {
                data.change("No." + 1);
                Thread.sleep(random.nextInt(5000));
                data.save();
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
